import java.util.InputMismatchException;
import java.util.Scanner;

public class Test {
    public static void func() throws NullPointerException {
        int[] array = null;
        System.out.println(array.length);
    }
public static int func2(){
        Scanner scanner = new Scanner(System.in);
        try{
           /* int a =10;
            return a;*/
            int[] array = {1,2,3,4};
            System.out.println(array[8]);
        }catch (InputMismatchException e){
            e.printStackTrace();
            System.out.println("捕获到了InputMismatchException异常");
        }finally {
            System.out.println("finally被执行了");
            scanner.close();
        }
        return -1;
}
    public static void main7(String[] args) {
     try {
         System.out.println(func2());
     }catch (ArrayIndexOutOfBoundsException e){
         e.printStackTrace();
         System.out.println("ArrayIndexOutofBoundsException");
     }finally {

     }
    }
    public static void main6(String[] args) {
        try(Scanner scanner = new Scanner(System.in)){
            int a = scanner.nextInt();
            System.out.println(a);
        }catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("捕获到了空指针异常");
        }catch (ArrayIndexOutOfBoundsException e){
            e.printStackTrace();
            System.out.println("捕获到了数组越界异常");
        }finally {
            System.out.println("finally被执行了");
        }
        System.out.println("hello");
    }
    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try{ int[] array = {1, 2, 3, 4};
            System.out.println(array[8]);

            int a = scanner.nextInt();
            System.out.println(a);
        }catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("捕获了空指针异常");
        }catch (ArrayIndexOutOfBoundsException e){
            e.printStackTrace();
            System.out.println("捕获了数组越界异常");
        }finally {
            System.out.println("finally被执行了");
            scanner.close();
        }
        System.out.println("hello");
    }
    public static void main4(String[] args) {
        try {
            int[] array = {1, 2, 3, 4};
            System.out.println(array[8]);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("捕获异常的方式不建议");
        }
        System.out.println("hello");
    }
    public static void main3(String[] args) {
        try {
            int[] array = {1, 2, 3, 4};
            System.out.println(array[8]);
        } catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("捕获到了空指针|数组越界异常");
        }
        System.out.println("hello");
    }
    public static void main2(String[] args) {
        try {
            int[] array = {1, 2, 3, 4};
            System.out.println(array[8]);
        } catch (NullPointerException e) {
            e.printStackTrace();
            System.out.println("捕获到了空指针异常");
        } catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("捕获到了数组越界异常");
        }
        System.out.println("hello");
    }

    public static void main1(String[] args) {
        try {
            func();
        } catch (NullPointerException e) {
            e.printStackTrace();
            System.out.println("处理NullPointerException异常");
        }
        System.out.println("hello");
    }

}